package com.lj.mcore.service;

import com.lj.mcore.dao.base.BaseAppDAO;
import com.lj.mcore.entity.GoodsStock;
import com.lj.mcore.execption.OutOfStockException;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
public class GoodsStockService implements IGoodsStockService{

    @Resource(name="goodsStockDao")
    private BaseAppDAO<GoodsStock> goodsStockDao;

    @Override
    public boolean save(GoodsStock obj) {
        return goodsStockDao.save(obj);
    }

    @Override
    public Boolean update(GoodsStock obj)  {

        if (obj.getStock()<0){
            /*throw new OutOfStockException("Inventory cannot be negative!");*/
            throw new RuntimeException("库存不能为负数");
        }

        System.out.println("@@@@@@@@@@@@@@@");
        return goodsStockDao.update(obj);
    }

    @Override
    public List<GoodsStock> query(String paramString, Map paramMap, int paramInt1, int paramInt2) {
        return goodsStockDao.query(paramString, paramMap, paramInt1, paramInt2);
    }

    @Override
    public GoodsStock getObjById(Long id) {
        return goodsStockDao.findById(id);
    }

    @Override
    public GoodsStock getSingleResult(Map<String, Object> map) {
        return goodsStockDao.getSingleResult(map);
    }


}
